#include <stdio.h>
#include <omp.h>

// 原func1函数，添加并行信息打印
void func1(int A[100][128]) {
    #pragma omp parallel
    {
        int thread_id = omp_get_thread_num();
        #pragma omp tile sizes(4, 4)
        #pragma omp tile sizes(5, 16)
        for (int i = 0; i < 100; ++i) {
            for (int j = 0; j < 128; ++j) {
                A[i][j] = i * 1000 + j;
                printf("Thread %d is processing A[%d][%d] in func1\n", thread_id, i, j);
            }
        }
    }
}

// 原func2函数，添加并行信息打印
void func2(int A[100][128]) {
    #pragma omp parallel
    {
        int thread_id = omp_get_thread_num();
        #pragma omp tile sizes(4, 4)
        for (int i1 = 0; i1 < 100; i1 += 5) {
            for (int j1 = 0; j1 < 128; j1 += 16) {
                for (int i2 = i1; i2 < i1 + 5; ++i2) {
                    for (int j2 = j1; j2 < j1 + 16; ++j2) {
                        A[i2][j2] = i2 * 1000 + j2;
                        printf("Thread %d is processing A[%d][%d] in func2\n", thread_id, i2, j2);
                    }
                }
            }
        }
    }
}

// 原func3函数，添加并行信息打印
void func3(int A[100][128]) {
    #pragma omp parallel
    {
        int thread_id = omp_get_thread_num();
        for (int i11 = 0; i11 < 100; i11 += 5 * 4) {
            for (int j11 = 0; j11 < 128; j11 += 16 * 4) {
                for (int i12 = i11; i12 < i11 + (5 * 4); i12 += 5) {
                    for (int j12 = j11; j12 < j11 + (16 * 4); j12 += 16) {
                        for (int i2 = i12; i2 < i12 + 5; ++i2) {
                            for (int j2 = j12; j2 < j12 + 16; ++j2) {
                                A[i2][j2] = i2 * 1000 + j2;
                                printf("Thread %d is processing A[%d][%d] in func3\n", thread_id, i2, j2);
                            }
                        }
                    }
                }
            }
        }
    }
}

int main() {
    int A[100][128];

    // 调用func1函数
    func1(A);

    // 输出A数组部分内容查看结果（可按需修改）
    printf("After func1:\n");
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            printf("%d ", A[i][j]);
        }
        printf("\n");
    }

    // 调用func2函数
    func2(A);

    // 输出A数组部分内容查看结果（可按需修改）
    printf("After func2:\n");
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            printf("%d ", A[i][j]);
        }
        printf("\n");
    }

    // 调用func3函数
    func3(A);

    // 输出A数组部分内容查看结果（可按需修改）
    printf("After func3:\n");
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            printf("%d ", A[i][j]);
        }
        printf("\n");
    }

    return 0;
}